package com.atguigu.day17.treeset.exer1;

import org.junit.Test;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/21 10:21
 * @注释
 */
public class Randon {
    @Test
    public void test01(){

        TreeSet<Integer> treeSet = new TreeSet<>();

        for (int i = 0; i < 10; i++) {
            int num = (int) (Math.random() * (29 - 20 + 1) + 20);
            if (treeSet.contains(num) == true){
                i--;
            }
            treeSet.add(num);
        }
        /*while (treeSet.size() < 10) {
            int num = (int) (Math.random() * (29 - 20 + 1) + 20);
            treeSet.add(num);
        }*/
        System.out.println(treeSet);
    }
}
